#!/bin/sh

#
# Test that metadata can be retreived from the commandline
#

. "$(cd "$(dirname "$0")" && pwd)/common.sh"

EXPECTED_OUTPUT=$WORK/expected_output
ACTUAL_OUTPUT=$WORK/actual_output

cat >$CONFIG <<EOF
meta-product = "product name"
meta-description = "product description"
meta-version = "some version"
meta-platform = "a platform"
meta-architecture = "an architecture"
meta-author = "someone"
EOF

cat >$EXPECTED_OUTPUT <<EOF
meta-product="product name"
meta-description="product description"
meta-version="some version"
meta-author="someone"
meta-platform="a platform"
meta-architecture="an architecture"
meta-creation-date="2018-05-05T18:10:16Z"
meta-uuid="ded51581-3c37-5dd5-d1b6-cd8503e4cfc4"
EOF

# Test the preferred way
SOURCE_DATE_EPOCH=1525543816 $FWUP_CREATE -c -f $CONFIG -o $FWFILE
$FWUP_APPLY_NO_CHECK -i $FWFILE -m > $ACTUAL_OUTPUT
diff -w $EXPECTED_OUTPUT $ACTUAL_OUTPUT

# Make sure the old way still works
(unset SOURCE_DATE_EPOCH && NOW="2018-05-05T18:10:16Z" $FWUP_CREATE -c -f $CONFIG -o $FWFILE)
$FWUP_APPLY_NO_CHECK -i $FWFILE -m > $ACTUAL_OUTPUT
diff -w $EXPECTED_OUTPUT $ACTUAL_OUTPUT

# Check that the verify logic works on this file
$FWUP_VERIFY -V -i $FWFILE
